<?php
namespace Home\Model;
use Think\Model;
class MemberModel extends Model {
    public function getSellerInfo($cond){

        if(!$cond){
    		return false;
    	}
    	$res = M('member')->join('join ecm_store on ecm_member.user_id = ecm_store.store_id')->where($cond)
    		->find();
    	return $res;
    }
    public function getMemberCount($cond){
        if(!$cond){
            return false;
        }
        $res = M('member')->field("count(*) as sum,FROM_UNIXTIME(reg_time, '%Y-%m-%d') as date,s_id,s_name")
            ->group('date')
            ->where($cond)
            ->select();

        return $res;
    }
    public function getAdminInfo($cond){
        if(!$cond){
            return false;
        }
        $memberInfo = $this->where(array('user_name'=>$cond['user_name']))->find();
        $code = 10010;
        $msg = '用户不存在';
        $data = array();
        if(!empty($memberInfo)){
            $msg = '密码错误';
            if($cond['password'] == $memberInfo['password']){
                $msg = '您没有权限访问';
                $userPriv = M("user_priv")->where(array('user_id'=>$memberInfo['user_id']))->find();
                if(!empty($userPriv) && $userPriv['store_id'] == 2 && $userPriv['privs'] == 'all'){
                    $code = 1;
                    $msg = 'success';
                    $data = $memberInfo;
                }
            }
        }
        return $arr = array('code'=>$code,'msg'=>$msg,'data'=>$data);
    }

    public function insertSellerInfo($data){
        if(!$data){
            return false;
        }
        $res = M('member')->add($data);
        return $res;
    }

    public function reviseSellerInfo($cond,$data){
        if(!$cond || !$data){
            return false;
        }
        $res = M('member')->where($cond)->save($data);
        return $res;
    }

}